import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import visualizer from "rollup-plugin-visualizer";

export default defineConfig({
  plugins: [
    vue(),
    visualizer({
      open: true, // 设置为 true 可以在构建完成后自动打开报告
      gzipSize: true,
      brotliSize: true,
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: true,
    port: 5713,
    proxy: {
      // '/translate': {
      //   target: 'https://fanyi-api.baidu.com',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/translate/, '')
      // },
      '/youdao': {
        target: 'https://openapi.youdao.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/youdao/, '')
      },
      '/movies': {
        target: 'https://oa.avdsr.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/movies/, '')
      },
      '/m3u8': {
        target: 'https://oa.avdsr.com/m3u8',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/m3u8/, '')
      },
    }
  },
  build: {
    target: "es2015",
    cssTarget: "chrome80",
  },
});
